package com.qfedu.mapper;

import com.qfedu.model.Branch;
import com.qfedu.model.TaskPlan;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * 概述:
 *
 * @Author: Tbh
 * @Date: 2022/7/1 20:21
 */

public interface TaskPlanMapper {

    @Results(id = "taskplanMap", value = {
            @Result(column = "tid", property = "tid"),
            @Result(column = "tname", property = "tname"),
            @Result(column = "starttime", property = "starttime"),
            @Result(column = "endtime", property = "endtime"),
            @Result(column = "updatetime", property = "updatetime"),
            @Result(column = "bid", property = "bid"),
            @Result(column = "bid", property = "branch", javaType = Branch.class, one =  //一对一关联查询
            @One(select = "com.qfedu.mapper.BranchMapper.findByBid", fetchType = FetchType.EAGER)
            ),
    })
    @Select("select * from taskplan where status = 1 limit #{currentPage},#{pageSize}")
    List<TaskPlan> findPage(@Param("currentPage") int currentPage, @Param("pageSize") Integer pageSize);

    @Select("select count(*) from taskplan where status = 1")
    Long count();

    @Insert("insert into taskplan (tid,tname,starttime,endtime,updatetime,bid) values " +
            "(#{tid},#{tname},#{starttime},#{endtime},#{updatetime},#{bid})")
    int addTaskPlan(TaskPlan taskPlan);

    @Select("select * from taskplan where status=1 and tid=#{tid}")
    TaskPlan findByTid(String tid);

    @Update("update taskplan set tname=#{tname},starttime=#{starttime}," +
            "endtime=#{endtime},bid=#{bid} where tid=#{tid}")
    int updateTaskPlan(TaskPlan taskPlan);

    @Update("update taskplan set status=0 where tid=#{tid}")
    int deleteByTid(String tid);
}
